package Code;

import java.util.Arrays;
import java.util.stream.Collectors;

public class Code238 {
    static int[] productExceptSelf(int[] nums){
        int n = nums.length;
        int[] res= new int[n];
        res[0] = 1;
        for(int i = 1; i<n; i++){
            res[i] = res[i-1] * nums[i-1];
        }
        int r= 1;
        for(int i = n-1; i>=0; i--){
            res[i] = res[i] * r;
            r = r* nums[i];
        }
        return res;
    }
    public static void main(String[] args) {
        System.out.println(Arrays.stream(productExceptSelf(new int[]{1,2,3,4})).boxed().collect(Collectors.toList()));
    }
}
